/** 带遮罩层loading license by http://eleadmin.com */
import { Message, Loading } from 'element-ui';

/**
 * 全局带遮罩层loading
 * @param options
 */
export default function(options) {
  if (typeof options === 'string') {
    options = { message: options };
  }
  const loading = Loading.service({
    spinner: 'none',
    background: options.background || 'transparent'
  });
  return Message(
    Object.assign(
      {
        duration: 0,
        customClass: 'ele-message-loading'
      },
      options,
      {
        onClose: (ins) => {
          loading.close();
          options.onClose && options.onClose(ins);
        }
      }
    )
  );
}
